"""多层感知机加载"""
from keras.models import load_model
from tensorflow.examples.tutorials.mnist import input_data
import matplotlib.pyplot as plt
import numpy as np

#模型加载
model_save_path="./Dense.h5"
model=load_model(model_save_path)

img_size=28
mnist=input_data.read_data_sets("./data",one_hot=True)
X_train,y_train,X_test,y_test=mnist.train.images,mnist.train.labels,mnist.test.images,mnist.test.labels
X_train=X_train.reshape(-1,img_size,img_size,1)
X_test=X_test.reshape(-1,img_size,img_size,1)
print(X_train[0].shape)
print(y_train[0].shape)
X_train=X_train.reshape(-1,img_size,img_size)
X_test=X_test.reshape(-1,img_size,img_size)
X_train=X_train*255
X_test=X_test*255

sample=X_test[0]
plt.imshow(sample, cmap=plt.get_cmap('gray'))
plt.show()

"""模型验证"""
#预处理至1维,且归一化
"""
reshape(1,-1)转化成1行：
reshape(2,-1)转换成两行：
reshape(-1,1)转换成1列：
reshape(-1,2)转化成两列
"""
sample=sample.reshape(1,-1)
print(sample.shape)
sample=sample/255

#预测
pred=model.predict(sample)
#输出为(1,10)
print(pred.shape)
predict = np.argmax(pred,axis=1) #axis = 1是取行的最大值的索引，0是列的最大值的索引
print(predict)